package com.xlf.common.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Model;
import com.xlf.common.model.Factory;
import com.xlf.web.SessionKey;

public class FactoryInterceptor implements Interceptor {

	@Override
	public void intercept(ActionInvocation ai) {
		Controller controller = ai.getController();
		Object factory = controller.getSessionAttr(SessionKey.USER);
		if(factory == null) {
			controller.setAttr("notice", "本操作必须使用厂家账号登陆完成");
			controller.redirect("/factory/login");
		} else {
			Object user = controller.getSessionAttr(SessionKey.USER);
			controller.setAttr("loginUserName", ((Model<Factory>) user).get("adminName"));
			
			ai.invoke();
		}
		

	}

}
